package com.itheima.controller;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.impl.ClazzServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 班级控制器
 * @author GY
 * @version V1.0
 * @date 2025-01-09 20:06
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    private final ClazzServiceImpl clazzsService;

    /**
     * 3.1班级列表查询
     */
    @GetMapping
    public Result  pageQuery(ClazzQueryParam clazzQueryParam){
        log.info("empQueryParam:{}", clazzQueryParam);
        PageResult<Clazz> pageResult = clazzsService. pageQuery(clazzQueryParam);
        return Result.success(pageResult);
    }

    /**
     * 3.2删除班级
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("id:{}",id);
        clazzsService.delete(id);
        return Result.success();
    }

    /**
     * 3.3添加班级
     */
    @PostMapping
    public Result insert(@RequestBody Clazz clazz){
        log.info("clazz:{}", clazz);
        clazzsService.insert(clazz);
        return Result.success();
    }

    /**
     * 3.4根据ID查询
     */
    @GetMapping("{id}")
    public Result findById(@PathVariable Integer id){
        log.info("id:{}",id);
        Clazz clazz = clazzsService.findById(id);
        return Result.success(clazz);
    }

    /**
     * 3.5修改班级
     */
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("clazz:{}", clazz);
        clazzsService.update(clazz);
        return Result.success();
    }

    /**
     * 查询全部班级
     */
    @GetMapping("/list")
    public Result findAll(){
        log.info("ClazzController findAll");
        List<Clazz> clazzs = clazzsService.findAll();
        return Result.success(clazzs);
    }

}
